<?php
namespace app\admin\controller;
use think\db;
use app\admin\model\Set as Set;
use app\admin\model\Conf as Confs;
class Config extends Common
{
    public function Config(){
        $data = Set::Where("type = 'conf' and c_status = 1")->order('c_sort')->paginate(10);
        $this->assign('set_data',$data);
        return view();
    }

    public function GetConfig(){

    }
    public function ConfigList(){
        if(request()->isAjax()){
            $data = input('post.');
            if(isset($data['file'])){
                unset($data['file']);
            }
            $rows = Confs::where('id','in',input('id'))->update($data);
            if($rows){
               $this->success('成功',url('Config/ConfigList'));
            }else{
                echo 2;
            }


        }
        $data = Set::Where("type = 'conf' and c_status = 1")->order('c_sort')->select();
        $ConfData = GetConfDate('id');
        $this->assign('set_data',$data);
        $this->assign('ConfData',$ConfData);
        return view();
    }
    public function ConfigTop(){

        return view();
    }

    public function cadd(){
        if(request()->isAjax()){
            $data = input('post.');
            $validate = validate('config');
            if(!$validate->scene('add')->check(input('post.'))){
                $this->error($validate->getError());
            }
            $data['type'] = 'conf';
            $add = db('set')->insertGetId($data);
            if($add){
                $tab = GetConf('conf');
                $cofRow = db::query("ALTER TABLE `$tab` ADD COLUMN `" . $data['ename'] . "` TEXT NOT NULL");
//                db('conf')->insert(['s_id'=>$add]);
                $this->success('添加成功！',url('cadd'));
            }else{
                $this->error('添加失败');
            }
        }

        return view();
    }
}